import heapq
class Solution(object):
    def maxResult(self, nums, k):
        st = [[- nums[0], 0]]
        n = len(nums)
        for index in range(1, n):
            while st and st[0][1] + k < index:
                heapq.heappop(st)
            val, _ = st[0]
            nums[index] -= val
            heapq.heappush(st, [-nums[index], index])
        return nums[-1]